//
//  YCHEOUNjoinTableViewCell.m
//  HeartWorldClient
//
//  Created by 董知樾 on 2016/11/16.
//  Copyright © 2016年 谭明权. All rights reserved.
//

#import "YCHEOUNjoinTableViewCell.h"
#import "YCHEOPersonModel.h"

@interface YCHEOUNjoinTableViewCell ()

@property (strong, nonatomic) UIView *contaierView;

@property (strong, nonatomic) UILabel *nameLabel;

@property (strong, nonatomic) UILabel *IDCardNumberLabel;

@property (strong, nonatomic) UIButton *rightAreaBtn;

@property (strong, nonatomic) UILabel *statusLabel;

@property (strong, nonatomic) UIImageView *tickImageView;

@property (copy, nonatomic) void (^didClickRightAreaBlock)(YCHEOPersonModel *model);

@end

@implementation YCHEOUNjoinTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
    //86
    CGFloat rightAreaW = 100;
    
    _rightAreaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _rightAreaBtn.layer.borderWidth = 1;
    _rightAreaBtn.layer.borderColor = [UIColor colorWithRGBValue:0xE7E7E7].CGColor;
    _contaierView.layer.masksToBounds = YES;
    [_rightAreaBtn addTarget:self action:@selector(didClickRightAreaBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_rightAreaBtn];
    [_rightAreaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(8);
        make.bottom.mas_equalTo(-8);
        make.trailing.mas_equalTo(-10);
        make.width.mas_equalTo(rightAreaW + 1);
    }];
    
    _statusLabel = [[UILabel alloc]init];
    _statusLabel.font = [UIFont systemFontOfSize:14];
    _statusLabel.textAlignment = NSTextAlignmentCenter;
//    _statusLabel.textColor = [UIColor YCBackWith:YCVIColorMain];
    _statusLabel.backgroundColor = [UIColor whiteColor];
    _statusLabel.layer.masksToBounds = YES;
    [_rightAreaBtn addSubview:_statusLabel];
    [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(_rightAreaBtn);
        make.centerY.equalTo(_rightAreaBtn);
    }];
    
    _contaierView = [[UIView alloc]init];
    _contaierView.backgroundColor = [UIColor whiteColor];
    _contaierView.layer.borderWidth = 1;
    _contaierView.layer.borderColor = [UIColor colorWithRGBValue:0xef4a65].CGColor;
    
   
    _contaierView.layer.masksToBounds = YES;
    [self.contentView addSubview:_contaierView];
    [_contaierView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(8, 10, 8,rightAreaW + 10));
    }
    ];
    
    _nameLabel = [[UILabel alloc]init];
    _nameLabel.font = [UIFont systemFontOfSize:14];
    _nameLabel.textColor = [UIColor colorWithRGBValue:0x333333];
    _nameLabel.layer.masksToBounds = YES;
    _nameLabel.backgroundColor = _contaierView.backgroundColor;
    [_contaierView addSubview:_nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(12);
        make.top.mas_equalTo(10);
    }];
    
    _IDCardNumberLabel = [[UILabel alloc]init];
    _IDCardNumberLabel.font = [UIFont systemFontOfSize:14];
    _IDCardNumberLabel.textColor = [UIColor colorWithRGBValue:0x999999];
    _IDCardNumberLabel.layer.masksToBounds = YES;
    _IDCardNumberLabel.backgroundColor = _contaierView.backgroundColor;
    [_contaierView addSubview:_IDCardNumberLabel];
    [_IDCardNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_nameLabel);
        make.bottom.mas_equalTo(-10);
    }];
    
    _tickImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tick_ corner"]];
    [_contaierView addSubview:_tickImageView];
    [_tickImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(35, 35));
        make.trailing.bottom.equalTo(_contaierView);
    }];
    
    _nameLabel.text = @"洪七公";
    _IDCardNumberLabel.text = @"4007**********1125";
    _statusLabel.text = @"待支付";
}

- (void)setModel:(YCHEOPersonModel *)model {
    _model = model;
    
    _nameLabel.text = [NSString stringWithFormat:@"姓名:%@",model.personName];
    
  
    _IDCardNumberLabel.text = [NSString stringWithFormat:@"身份证:%@",model.personIDCard?:@"暂无数据"];
   
    
    _statusLabel.text = @"加入援助";
    
    _tickImageView.hidden = !model.selected;
    _contaierView.layer.borderColor = model.selected ? [UIColor colorWithRGBValue:0xef4a65].CGColor : [UIColor colorWithRGBValue:0xE7E7E7].CGColor;
}

- (void)didClickRightAreaBtn:(UIButton *)btn {
    if (_didClickRightAreaBlock) {
        _didClickRightAreaBlock(_model);
    }
}

- (void)didClickRightArea:(void (^)(YCHEOPersonModel *model))block {
    _didClickRightAreaBlock = block;
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
//    _model.selected = selected;
//    _contaierView.layer.borderColor = _model.selected ? [UIColor colorWithRGBValue:0xef4a65].CGColor : [UIColor colorWithRGBValue:0x999999].CGColor; ;
}

@end
